home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / ARexxTools / dofile20.lha / dofile / dofile.rexx < prev   
Encoding:
OS/2 REXX Batch file  |  1995-12-31  |  2.9 KB  |  109 lines

  1. /*
  2. ** $VER: dofile.rexx 2.0 (30.12.95) Rolf Rotvel
  3. **
  4. ** Uses datatypes.library & rexxreqtools.library
  5. */
  6.  
  7. cfgfile = 'env:dofile.prefs'                    /* Path to prefs file */
  8. defdir = 'txt:'                                 /* Defdir for filerequester */
  9. multicmd = 'sys:utilities/multiview screen'     /* Path (& options) to Multiview */
  10.  
  11. /*
  12. ** End cfg.
  13. */
  14.  
  15. /* Load libraries */
  16. call addlib('rexxsupport.library', 0, -30, 0)
  17. call addlib('rexxreqtools.library', 0, -30, 0)
  18. call addlib('datatypes.library', 0, -30)
  19.  
  20. /* Get version info from $VER line */
  21. version = subword(sourceline(2), 3, 2) 
  22. /* Check defdir */
  23. if defdir = '' | ~exists(defdir) then defdir = pragma('d')
  24.  
  25. /* Open cfgfile - exit if fail - read it otherwise */
  26. if ~open('tmp', cfgfile, 'r') then do
  27.     call rtezrequest('Couldn''t open '||cfgfile,, version)
  28.     exit 10
  29. end
  30. cfg = ' '||translate(readch('tmp', 65535), '', '0a'x)
  31. call close('tmp')
  32.  
  33. /* If no arg then open filerequester */
  34. if arg() = 0 then txt = gettxt(defdir)
  35. else do 
  36.     /* Get args and remove quotes - if any */
  37.     txt = dequote(arg(1))
  38.     /* Handle special cases (File = .info or file = dir) */
  39.     select
  40.         when ~exists(txt) then txt = txt||'.info'
  41.         when word(statef(txt), 1) = 'DIR' then txt = gettxt(txt)
  42.         otherwise nop
  43.     end
  44. end
  45.  
  46. /* Simple error handling */
  47. if ~exists(txt) then exit 10
  48. if word(statef(txt), 2) = 0 then exit 10
  49.  
  50. /* Get (data)type of file */
  51. type = filetype(txt)
  52.  
  53. /* Check ascii & binary files for special cases */
  54. if type = 'ascii' | type = 'binary' then do
  55.     name = getname(txt)
  56.     parse upper var name base '.' suff
  57.     /* Filename has an extension */
  58.     if suff ~= '' then do
  59.         /* We found a match in cfg file */
  60.         if pos(' .'||suff||' ', cfg) > 0 then type = '.'||suff
  61.         /* No match -> check binary files for MOD. type names */
  62.         if type = 'binary' then do
  63.             if pos(' '||base||'. ', upper(cfg)) > 0 then type = base||'.'
  64.         end
  65.     end
  66. end
  67.  
  68. /* Didn't find any file to process? */
  69. if type = 'binary' then do
  70.     /* Check for binary entry in cfg file */
  71.     if pos(' '||type||' ', cfg) = 0 then do
  72.         call rtezrequest('Couldn''t process:'||'0a'x||txt,, version)
  73.         exit
  74.     end
  75. end
  76.  
  77.  
  78. /* Find the cmd associated with the filetype and do it */
  79. type = ' '||type||' '
  80. parse var cfg . (type) '"' cmd '"' .
  81. /* Fall back on Multiview */
  82. if cmd = '' then cmd = multicmd
  83. /* Do it! */
  84. say 'Filetype : '||strip(type)
  85. say 'Command  : '||cmd||' "'||txt||'"'
  86. address command cmd '"'||txt||'"'
  87. exit
  88.  
  89.  
  90. GETTXT:
  91. parse arg dir
  92. txt = rtfilerequest(dir,, version,, 'rt_screentofront=true')
  93. if txt = '' then exit
  94. return dequote(txt)
  95.  
  96. FILETYPE: procedure
  97. parse arg file
  98. return strip(translate(examinedt(file,,), '', '0'x))
  99.  
  100. DEQUOTE: procedure
  101. parse arg str
  102. parse var str '"' unq '"'
  103. if unq ~= '' then return unq
  104. return str
  105.  
  106. GETNAME: procedure
  107. parse arg path
  108. return strip(substr(path, max(pos(':', path), lastpos('/', path)) + 1))
  109.